package com.bruan.d8_arrays;

import java.util.Arrays;
import java.util.Comparator;

public class Test {
    public static void main(String[] args) {
        Student[] students = new Student[5];
        students[0] = new Student("xx1",11,"16661661616");
        students[1] = new Student("xx2",12,"16661661616");
        students[2]= new Student("xx5",14,"16661661616");
        students[3] = new Student("xx3",12,"16661661616");
        students[4] = new Student("xx4",23,"16661661616");

        Arrays.sort(students);
        System.out.println(Arrays.toString(students));

        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                if(o1.getAge() > o2.getAge()){
                    return 1;
                }else if (o1.getAge()<o2.getAge()){
                    return -1;
                }
                return 0;
//                return o1.getAge()-o2.getAge();//整数情况
// return Double.compare(o1.getAge(),o2.getAge());
                //
            }
        });
        System.out.println(Arrays.toString(students));

    }

}
